package com.cskayan.javase.object._3equals;
/**
 * 
 * @since 17:12
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo3 {
}
class Dog{
    int age;
    double price;

    public Dog() {
    }

    public Dog(int age, double price) {
        this.age = age;
        this.price = price;
    }

    @Override
    public boolean equals(Object o) {
        // 自反性
        if (this == o) return true;
        // 排它性 用instanceof,允许子类对象传入
        if (!(o instanceof Dog)) return false;

        Dog dog = (Dog) o;
        // 比较成员变量的取值
        if (age != dog.age) return false;
        return Double.compare(dog.price, price) == 0;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = age;
        temp = Double.doubleToLongBits(price);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}